package com.iss.apartmentmanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iss.apartmentmanage.entity.CheckinRecord;
import com.iss.apartmentmanage.mapper.CheckinRecordMapper;
import com.iss.apartmentmanage.mapper.RoomManagerMapper;
import com.iss.apartmentmanage.model.RecordWithRoom;
import com.iss.apartmentmanage.model.RecordWithRoomForAll;
import com.iss.apartmentmanage.service.CheckInRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CheckinRecordServiceImpl implements CheckInRecordService {
    @Autowired
    CheckinRecordMapper checkinRecordMapper;
    @Autowired
    RoomManagerMapper roomManagerMapper;
    /**
     * 登记入住信息
     * @param recordWithRoom
     * @return
     */
    @Override
    public Integer addCheckinRecord(RecordWithRoom recordWithRoom) {
        int insert = 0;
        try {
            if (recordWithRoom.getCheckinRecord() != null) {
                insert = checkinRecordMapper.insert(recordWithRoom.getCheckinRecord());
                recordWithRoom.getRoom().setStatus(1);
                roomManagerMapper.updateById(recordWithRoom.getRoom());
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return insert;
    }

    /**
     * 查看全部的订单记录
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public   List<RecordWithRoomForAll> selectAllCheckInRecord(int pageNum, int pageSize) {
        List<RecordWithRoomForAll> recordWithRoomForAll = checkinRecordMapper.selectAllCheckinRecord(pageNum, pageSize);
        return recordWithRoomForAll;
    }

    /**
     * 办理退房页面中查看客户的详细信息
     * @param id
     * @return
     */
    @Override
    public CheckinRecord selectGuestMessageByRoom(int id) {
        CheckinRecord record = new CheckinRecord();
        if(id!=0){
            record  = checkinRecordMapper.selectGuestMessageByRoom(id);
        }
        return record;
    }


}
